<template>
  <view class="page-loading" v-if="show" :style="{background:bgColor}">
    <view v-if="type == 'rotate'" class="loader" :class="className">
      <view>
        <view>
          <view>
            <view>
              <view>
                <view>
                  <view v-if="className == 'loader4'">
                    <view>
                      <view>
                        <view></view>
                      </view>
                    </view>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view v-else-if="type == 'spin'" class="loader-inner">
      <view class="loader-line-wrap">
        <view class="loader-line"></view>
      </view>
      <view class="loader-line-wrap">
        <view class="loader-line"></view>
      </view>
      <view class="loader-line-wrap">
        <view class="loader-line"></view>
      </view>
      <view class="loader-line-wrap">
        <view class="loader-line"></view>
      </view>
      <view class="loader-line-wrap">
        <view class="loader-line"></view>
      </view>
    </view>

    <view v-else-if="type == 'dots'" class="loader-dots">
      <view class="dot white"></view>
      <view class="dot"></view>
      <view class="dot"></view>
      <view class="dot"></view>
      <view class="dot"></view>
    </view>

    <view v-else-if="type == 'slide'" class="loader-slide">
      <view class="slide"></view>
      <view class="slide"></view>
      <view class="slide"></view>
      <view class="slide"></view>
      <view class="slide"></view>
    </view>

    <view v-else-if="type == 'loadit'" class="loader-loadit"></view>
  </view>
</template>

<script>
export default {
  name: "tuiPageLoading",
  props: {
    // rotate spin dots slide loadit
    type: {
      type: String,
      default: "rotate"
    },
    // type=rotate::loader1 loader2 loader3 loader4
    className: {
      type: [String, Array, Object],
      default: "loader1"
    },
    show: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {};
  },
  computed: {
    bgColor() {
      switch (this.type) {
        case "loadit":
          return "rgb(52,73,94,0.8)";
          break;
        case "spin":
          return "rgba(0,0,0,0.8)";
          break;
        case "dots":
          return "rgb(34,34,34,0.8)";
          break;
        case "rotate":
        default:
          return "rgba(255,255,255,0.8)";
          break;
      }
    }
  }
};
</script>

<style>
.page-loading {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1024;
  background: rgba(0, 0, 0, 0.5);
}
/* rotate start */
.loader {
  position: relative;
  margin: 75rpx auto;
  width: 200rpx;
  height: 200rpx !important;
  display: block;
  overflow: hidden;
}
.loader view {
  /* height: 100%; */
  height: calc(100% - 30rpx);
}

/* loader 1 */
.loader1,
.loader1 view {
  border-radius: 50%;
  padding: 12rpx;
  border: 4rpx solid transparent;
  -webkit-animation: rotate linear 3.5s infinite;
  animation: rotate linear 3.5s infinite;
  border-top-color: rgba(0, 0, 0, 0.5);
  border-bottom-color: #6cc;
}

/*loader 2  */
.loader2,
.loader2 view {
  border-radius: 50%;
  padding: 12rpx;
  border: 4rpx solid transparent;
  -webkit-animation: rotate linear 3.5s infinite;
  animation: rotate linear 3.5s infinite;
  border-top-color: #6cc;
  border-left-color: rgba(0, 0, 0, 0.5);
  border-right-color: rgba(0, 0, 0, 0.5);
}

/*loader 3  */
.loader3,
.loader3 view {
  border-radius: 50%;
  padding: 12rpx;
  border: 4rpx solid transparent;
  -webkit-animation: rotate linear 3.5s infinite;
  animation: rotate linear 3.5s infinite;
  border-top-color: rgba(0, 0, 0, 0.5);
  border-left-color: #6cc;
  -webkit-animation-timing-function: cubic-bezier(0.55, 0.38, 0.21, 0.88);
  animation-timing-function: cubic-bezier(0.55, 0.38, 0.21, 0.88);
  -webkit-animation-duration: 3s;
  animation-duration: 3s;
}

/* loader 4 */
.loader4,
.loader4 view {
  border-radius: 50%;
  border: 4rpx solid transparent;
  padding: 6rpx;
  -webkit-animation: rotate2 4s infinite linear;
  animation: rotate2 4s infinite linear;
  height: calc(100% - 18rpx);
}

view.loader:hover {
  -webkit-animation-play-state: paused;
  animation-play-state: paused;
}
.loader,
.loader * {
  will-change: transform;
}

@-webkit-keyframes rotate {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  50% {
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotate {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  50% {
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-webkit-keyframes rotate2 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
    border-top-color: rgba(0, 0, 0, 0.5);
  }
  50% {
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
    border-top-color: #6cc;
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
    border-top-color: rgba(0, 0, 0, 0.5);
  }
}
@keyframes rotate2 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
    border-top-color: rgba(0, 0, 0, 0.5);
  }
  50% {
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
    border-top-color: #6cc;
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
    border-top-color: #6cc;
  }
}
/* rotate end */
/* spin start */
.loader-inner {
  position: relative;
  height: 120rpx;
  width: 200rpx;
}

.loader-line-wrap {
  -webkit-animation: spin 2000ms cubic-bezier(0.175, 0.885, 0.32, 1.275)
    infinite;
  animation: spin 2000ms cubic-bezier(0.175, 0.885, 0.32, 1.275) infinite;
  box-sizing: border-box;
  height: 100rpx;
  left: 0;
  overflow: hidden;
  position: absolute;
  top: 0;
  -webkit-transform-origin: 50% 100%;
  transform-origin: 50% 100%;
  width: 200rpx;
}
.loader-line {
  border: 8rpx solid transparent;
  border-radius: 100%;
  box-sizing: border-box;
  height: 200rpx;
  left: 0;
  margin: 0 auto;
  position: absolute;
  right: 0;
  top: 0;
  width: 200rpx;
}
.loader-line-wrap:nth-child(1) {
  -webkit-animation-delay: -50ms;
  animation-delay: -50ms;
}
.loader-line-wrap:nth-child(2) {
  -webkit-animation-delay: -100ms;
  animation-delay: -100ms;
}
.loader-line-wrap:nth-child(3) {
  -webkit-animation-delay: -150ms;
  animation-delay: -150ms;
}
.loader-line-wrap:nth-child(4) {
  -webkit-animation-delay: -200ms;
  animation-delay: -200ms;
}
.loader-line-wrap:nth-child(5) {
  -webkit-animation-delay: -250ms;
  animation-delay: -250ms;
}

.loader-line-wrap:nth-child(1) .loader-line {
  border-color: hsl(0, 80%, 60%);
  height: 180rpx;
  width: 180rpx;
  top: 14rpx;
}
.loader-line-wrap:nth-child(2) .loader-line {
  border-color: hsl(60, 80%, 60%);
  height: 152rpx;
  width: 152rpx;
  top: 28rpx;
}
.loader-line-wrap:nth-child(3) .loader-line {
  border-color: hsl(120, 80%, 60%);
  height: 124rpx;
  width: 124rpx;
  top: 42rpx;
}
.loader-line-wrap:nth-child(4) .loader-line {
  border-color: hsl(180, 80%, 60%);
  height: 96rpx;
  width: 96rpx;
  top: 56rpx;
}
.loader-line-wrap:nth-child(5) .loader-line {
  border-color: hsl(240, 80%, 60%);
  height: 68rpx;
  width: 68rpx;
  top: 70rpx;
}

@-webkit-keyframes spin {
  0%,
  15% {
    -webkit-transform: rotate(0);
    transform: rotate(0);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

@keyframes spin {
  0%,
  15% {
    -webkit-transform: rotate(0);
    transform: rotate(0);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
/* spin end */
/* dots start */
.loader-dots {
  position: relative;
  width: 6.25em;
  height: 6.25em;
  animation: dot 2.4s linear infinite;
}
.white {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  animation: flash 2.4s linear infinite;
  opacity: 0;
}
.dot {
  position: absolute;
  margin: auto;
  width: 2.4em;
  height: 2.4em;
  border-radius: 100%;
  transition: all 1s ease;
}
.dot:nth-child(2) {
  top: 0;
  bottom: 0;
  left: 0;
  background: #ff4444;
  animation: dotsY 2.4s linear infinite;
}
.dot:nth-child(3) {
  left: 0;
  right: 0;
  top: 0;
  background: #ffbb33;
  animation: dotsX 2.4s linear infinite;
}
.dot:nth-child(4) {
  top: 0;
  bottom: 0;
  right: 0;
  background: #99cc00;
  animation: dotsY 2.4s linear infinite;
}
.dot:nth-child(5) {
  left: 0;
  right: 0;
  bottom: 0;
  background: #33b5e5;
  animation: dotsX 2.4s linear infinite;
}

@keyframes dot {
  0% {
    transform: rotate(0);
  }
  10% {
    width: 6.25em;
    height: 6.25em;
  }
  66% {
    width: 2.4em;
    height: 2.4em;
  }
  100% {
    transform: rotate(360deg);
    width: 6.25em;
    height: 6.25em;
  }
}

@keyframes dotsY {
  66% {
    opacity: 0.1;
    width: 2.4em;
  }
  77% {
    opacity: 1;
    width: 0;
  }
}
@keyframes dotsX {
  66% {
    opacity: 0.1;
    height: 2.4em;
  }
  77% {
    opacity: 1;
    height: 0;
  }
}

@keyframes flash {
  33% {
    opacity: 0;
    border-radius: 0%;
  }
  55% {
    opacity: 0.6;
    border-radius: 100%;
  }
  66% {
    opacity: 0;
  }
}
/* dots end */
/* slide start */
.loader-slide {
  position: absolute;
  top: 50%;
  left: 40%;
  margin-left: 10%;
  transform: translate3d(-50%, -50%, 0);
}
.slide {
  width: 48rpx;
  height: 48rpx;
  background: #3ac;
  border-radius: 100%;
  display: inline-block;
  animation: slide 1s infinite;
}
.slide:nth-child(1) {
  animation-delay: 0.1s;
  background: #32aacc;
}
.slide:nth-child(2) {
  animation-delay: 0.2s;
  background: #64aacc;
}
.slide:nth-child(3) {
  animation-delay: 0.3s;
  background: #96aacc;
}
.slide:nth-child(4) {
  animation-delay: 0.4s;
  background: #c8aacc;
}
.slide:nth-child(5) {
  animation-delay: 0.5s;
  background: #faaacc;
}
@-moz-keyframes slide {
  0% {
    transform: scale(1);
  }
  50% {
    opacity: 0.3;
    transform: scale(2);
  }
  100% {
    transform: scale(1);
  }
}
@-webkit-keyframes slide {
  0% {
    transform: scale(1);
  }
  50% {
    opacity: 0.3;
    transform: scale(2);
  }
  100% {
    transform: scale(1);
  }
}
@-o-keyframes slide {
  0% {
    transform: scale(1);
  }
  50% {
    opacity: 0.3;
    transform: scale(2);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes slide {
  0% {
    transform: scale(1);
  }
  50% {
    opacity: 0.3;
    transform: scale(2);
  }
  100% {
    transform: scale(1);
  }
}
/* slide end */
/* loadit start */
.loader-loadit {
  height: 3em;
  width: 3em;
  animation: loadit 4s linear infinite;
}
@keyframes loadit {
  55% {
    background: rgba(189, 195, 199, 0.4);
    border-radius: 100%;
    transform: rotate(360deg);
    box-shadow: 7em 0 0 rgba(189, 195, 199, 0.3),
      -7em 0 0 rgba(189, 195, 199, 0.3), 3em 0 0 rgba(189, 195, 199, 0.3),
      -3em 0 0 rgba(189, 195, 199, 0.3), 0 7em 0 rgba(189, 195, 199, 0.3),
      0 -7em 0 rgba(189, 195, 199, 0.3), 0 3em 0 rgba(189, 195, 199, 0.3),
      0 -3em 0 rgba(189, 195, 199, 0.3);
  }
}
/* loadit end */
</style>